/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author anhvh_b00319
 */
@Entity
@Table(name = "Staff")
@NamedQueries({
    @NamedQuery(name = "Staff.findAll", query = "SELECT s FROM Staff s"),
    @NamedQuery(name = "Staff.findByStaID", query = "SELECT s FROM Staff s WHERE s.staID = :staID"),
    @NamedQuery(name = "Staff.findByStaUserName", query = "SELECT s FROM Staff s WHERE s.staUserName = :staUserName"),
    @NamedQuery(name = "Staff.findByStaPassword", query = "SELECT s FROM Staff s WHERE s.staPassword = :staPassword"),
    @NamedQuery(name = "Staff.findByStaFullName", query = "SELECT s FROM Staff s WHERE s.staFullName = :staFullName"),
    @NamedQuery(name = "Staff.findByStaAddress", query = "SELECT s FROM Staff s WHERE s.staAddress = :staAddress"),
    @NamedQuery(name = "Staff.findByStaEmail", query = "SELECT s FROM Staff s WHERE s.staEmail = :staEmail"),
    @NamedQuery(name = "Staff.findByStatus", query = "SELECT s FROM Staff s WHERE s.status = :status")})
public class Staff implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "Sta_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer staID;
    @Basic(optional = false)
    @Column(name = "Sta_UserName")
    private String staUserName;
    @Basic(optional = false)
    @Column(name = "Sta_Password")
    private String staPassword;
    @Basic(optional = false)
    @Column(name = "Sta_FullName")
    private String staFullName;
    @Basic(optional = false)
    @Column(name = "Sta_Address")
    private String staAddress;
    @Basic(optional = false)
    @Column(name = "Sta_Email")
    private String staEmail;
    @Basic(optional = false)
    @Column(name = "Status")
    private boolean status;
    @Transient
    private String roleName;
    @Transient
    private Boolean Admin;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "teacher")
    private List<Program> programList;


    public Staff() {
        status = false;
        programList = new ArrayList<Program>();
    }

    public Staff(Integer staID) {
        this.staID = staID;
    }

    public Staff(Integer staID, String staUserName, String staPassword, String staFullName, String staAddress, String staEmail, boolean status) {
        this.staID = staID;
        this.staUserName = staUserName;
        this.staPassword = staPassword;
        this.staFullName = staFullName;
        this.staAddress = staAddress;
        this.staEmail = staEmail;
        this.status = status;
    }

    public Integer getStaID() {
        return staID;
    }

    public void setStaID(Integer staID) {
        Integer oldStaID = this.staID;
        this.staID = staID;
        changeSupport.firePropertyChange("staID", oldStaID, staID);
    }

    public String getStaUserName() {
        return staUserName;
    }

    public void setStaUserName(String staUserName) {
        String oldStaUserName = this.staUserName;
        this.staUserName = staUserName;
        changeSupport.firePropertyChange("staUserName", oldStaUserName, staUserName);
    }

    public String getStaPassword() {
        return staPassword;
    }

    public void setStaPassword(String staPassword) {
        String oldStaPassword = this.staPassword;
        this.staPassword = staPassword;
        changeSupport.firePropertyChange("staPassword", oldStaPassword, staPassword);
    }

    public String getStaFullName() {
        return staFullName;
    }

    public void setStaFullName(String staFullName) {
        String oldStaFullName = this.staFullName;
        this.staFullName = staFullName;
        changeSupport.firePropertyChange("staFullName", oldStaFullName, staFullName);
    }

    public String getStaAddress() {
        return staAddress;
    }

    public void setStaAddress(String staAddress) {
        String oldStaAddress = this.staAddress;
        this.staAddress = staAddress;
        changeSupport.firePropertyChange("staAddress", oldStaAddress, staAddress);
    }

    public String getStaEmail() {
        return staEmail;
    }

    public void setStaEmail(String staEmail) {
        String oldStaEmail = this.staEmail;
        this.staEmail = staEmail;
        changeSupport.firePropertyChange("staEmail", oldStaEmail, staEmail);
    }

    public boolean getStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        boolean oldStatus = this.status;
        this.status = status;
        changeSupport.firePropertyChange("status", oldStatus, status);
    }

    public String getRoleName() {
        if (status) {
            roleName = "Admin";
        } else {
            roleName = "Staff";
        }
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public List<Program> getProgramList() {
        return programList;
    }

    public void setProgramList(List<Program> programList) {
        this.programList = programList;
    }

    public Boolean isAdmin() {
        return status;
    }

    public void setAdmin(Boolean Admin) {
        this.Admin = Admin;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (staID != null ? staID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Staff)) {
            return false;
        }
        Staff other = (Staff) object;
        if ((this.staID == null && other.staID != null) || (this.staID != null && !this.staID.equals(other.staID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return staFullName;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
